home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / HDX_BACK / HDXPCH / EPART.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  8.6 KB  |  413 lines

  1.  
  2. /* epart.c */
  3.  
  4. /*
  5.  * Partition edit and pick for MS-DOS
  6.  *
  7.  * 08-Oct-1988    jye.  change and add this codes to do the partition 
  8.  *                       editing and picking for MS-DOS
  9.  * 18-NOV-1988  jye.  change and add codes in the partition editing and
  10.  *                      picking for the user interface.
  11.  */
  12.  
  13. #include "obdefs.h"
  14. #include "gemdefs.h"
  15. #include "osbind.h"
  16. #include "mydefs.h"
  17. #include "part.h"
  18. #include "ipart.h"
  19. #include "bsl.h"
  20. #include "hdxpch.h"
  21. #include "addr.h"
  22. #include "myerror.h"
  23.  
  24. extern int typedev;
  25. extern int typedrv;
  26. extern char sbuf[];
  27. extern int npart;                /* number of partitions */
  28. extern int ext;                /* the index of extended partition */
  29.  
  30. /*
  31.  * Global variables these routines communicate with
  32.  *
  33.  */
  34. static PART *pinfo;        /* -> partition block */
  35. static int totcyl;        /* total # of cylinder */
  36. static long sizleft;    /* size of unused disk in blocks */
  37. static long extleft;    /* size of unused extended partition in blocks */
  38. static int formw, formh;
  39. static int lx, ly, sx, sy;
  40. static int ok2draw;        /* 0: don't draw PARTPNL boxes */
  41. static int pnlflg;        /* 1: partition scheme comes from panel */
  42. static int along;        /* 1: will not redraw and clean the box */
  43. static int lowlim;        /* index of dialog box */
  44. static int first;        /* flag for add bad and good sectors only one time */
  45. long disksiz;            /* size of disk in blocks */
  46. long sumsiz;            /* the sum of bytes of root sectors */
  47. long spcyl;                /* sector per cylinder */
  48. long sptrk;                /* sector per track */
  49. int yesscan;            /* the flag for the func. IBMGPART use */
  50. int tolpart;            /* the total of number partitions */
  51. int epty;                /* the y-coordinate of the moving bar */
  52. int restept;            /* 1: rest the moving bar to initial place */
  53.  
  54.  
  55.  
  56. #define MFM 17            /* sectors per track of MFM */
  57. #define RLL 26            /* sectors per track of RLL */
  58.  
  59.  
  60. /* 
  61.  * get ST partition information for ST structure
  62.  */
  63.  
  64. stgpart(xdev, bs, rpinfo)
  65.  
  66. int xdev;
  67. char *bs;
  68. PART **rpinfo;
  69.  
  70. {
  71.     int i, j, linkst, ret;
  72.     long sect;
  73.     register PART *ipart;
  74.     PART *xpinfo;
  75.  
  76.     if ((npart = countpart(xdev)) == ERROR)    {
  77.         return ERROR;
  78.     }
  79.     if ((*rpinfo = (PART *)Malloc((long)sizeof(PART)*npart)) <= 0)    {
  80.         err(nomemory);
  81.         if (rpinfo > 0)        Mfree(rpinfo);
  82.         return ERROR;
  83.     }
  84.     xpinfo = *rpinfo;
  85.     inipart(xpinfo, npart);
  86.        ipart = &((RSECT *)(bs + 0x200 - sizeof(RSECT)))->hd_p[0];
  87.     for (i = 0; i < NPARTS; i++, ipart++)    {
  88.         xpinfo[i].p_flg = ipart->p_flg;
  89.         xpinfo[i].p_st = ipart->p_st;
  90.         xpinfo[i].p_siz = ipart->p_siz;
  91.         if (ipart->p_flg & P_EXISTS)    {
  92.             if (i == ext)        {
  93.                 xpinfo[i].p_id[0] = 'X';
  94.                 xpinfo[i].p_id[1]  ='G';
  95.                 xpinfo[i].p_id[2] = 'M';
  96.             } else if (xpinfo[i].p_siz < MB16)    {
  97.                 xpinfo[i].p_id[0] = 'G';
  98.                 xpinfo[i].p_id[1]  ='E';
  99.                 xpinfo[i].p_id[2] = 'M';
  100.             } else {
  101.                 xpinfo[i].p_id[0] = 'B';
  102.                 xpinfo[i].p_id[1]  ='G';
  103.                 xpinfo[i].p_id[2] = 'M';
  104.             }
  105.         }
  106.     }
  107.     if (ext != NO_EXT)    { /* there are extended partition */
  108.         sect = xpinfo[ext].p_st;
  109.         do    {
  110.             if ((ret = getroot(xdev, bs, sect)) != 0) {
  111.                     if (tsterr(ret) != OK)
  112.                     err(rootread);
  113.                 return ERROR;
  114.             }
  115.                ipart = &((RSECT *)(bs + 0x200 - sizeof(RSECT)))->hd_p[0];
  116.             xpinfo[i].p_flg = ipart->p_flg;
  117.             xpinfo[i].p_st = sect;
  118.             xpinfo[i].p_siz = ipart->p_siz + ROOTSECT;
  119.             if (xpinfo[i].p_siz < MB16)    {
  120.                 xpinfo[i].p_id[0] = 'G';
  121.                 xpinfo[i].p_id[1]  ='E';
  122.                 xpinfo[i].p_id[2] = 'M';
  123.             } else {
  124.                 xpinfo[i].p_id[0] = 'B';
  125.                 xpinfo[i].p_id[1]  ='G';
  126.                 xpinfo[i].p_id[2] = 'M';
  127.             }
  128.             ipart++;                
  129.             i++;
  130.             sect = ipart->p_st + xpinfo[ext].p_st;
  131.         } while ((ipart->p_id[0] == 'X') && (ipart->p_id[1] == 'G') &&
  132.                 (ipart->p_id[2] == 'M'));  /* more partition */
  133.     } 
  134.     return OK;
  135. }
  136.  
  137.  
  138.  
  139.  
  140.  
  141. inipart(xpart, npart)
  142. PART *xpart;
  143. int npart;
  144. {
  145.     int i;
  146.  
  147.     for (i = 0; i < npart; i++)    {
  148.         xpart[i].p_siz = 0L;
  149.         xpart[i].p_flg = 0;
  150.         xpart[i].p_st = 0L;
  151.         xpart[i].p_id[0] = 0;
  152.         xpart[i].p_id[1] = 0;
  153.         xpart[i].p_id[2] = 0;
  154.     }
  155. }
  156.  
  157.  
  158.  
  159.  
  160. countpart(dev)
  161. int dev;
  162. {
  163.     char bs[512];
  164.     PART *ipart;
  165.     int ret, count, i; 
  166.     long sect, start;
  167.     if ((ret = getroot(dev, bs, (SECTOR)0)) != 0)    {
  168.         if (tsterr(ret) != OK)
  169.             err(rootread);
  170.         return ERROR;
  171.     }
  172.     ipart = &((RSECT *)(bs + 0x200 - sizeof(RSECT)))->hd_p[0];
  173.     ext = NO_EXT;
  174.     for (i=0; i < NPARTS; i++, ipart++)    {
  175.         if ((ipart->p_flg & P_EXISTS) && 
  176.                 (ipart->p_id[0] == 'X') && 
  177.                 (ipart->p_id[1] == 'G') && 
  178.                 (ipart->p_id[2] == 'M'))    {
  179.             ext = i;
  180.             start = ipart->p_st;
  181.         }
  182.     }
  183.     count = 4;
  184.     if (ext != NO_EXT)    {
  185.         sect = start;
  186.         do    {
  187.             if ((ret = getroot(dev, bs, sect)) != 0)    {
  188.                 if (tsterr(ret) != OK)
  189.                     err(rootread);
  190.                 return ERROR;
  191.             }
  192.                ipart = &((RSECT *)(bs + 0x200 - sizeof(RSECT)))->hd_p[0];
  193.             count++;
  194.             ipart++;                
  195.             sect = ipart->p_st + start;
  196.         } while ((ipart->p_id[0] == 'X') && (ipart->p_id[1] == 'G') &&
  197.                 (ipart->p_id[2] == 'M'));  /* more partition */
  198.     } 
  199.     return (count);
  200. }
  201.  
  202.  
  203.  
  204. /*
  205.  * Force checksum of sector image to a value
  206.  */
  207. forcesum(image, sum)
  208. UWORD *image;
  209. UWORD sum;
  210. {
  211.     register int i;
  212.     register UWORD w;
  213.  
  214.     w = 0;
  215.     /* up limit is half of buffer size - 2 */
  216.     for (i = 0; i < ((UWORD)BPS/2 - 1); ++i)
  217.     w += *image++;
  218.     *image++ = sum - w;
  219. }
  220.  
  221.  
  222. /*
  223.  * Put word in memory in 8086 byte-reversed format.
  224.  *
  225.  */
  226. iw(wp, w)
  227. UWORD *wp;
  228. UWORD w;
  229. {
  230.     char *p;
  231.  
  232.     p = (char *)wp;
  233.     p[0] = (w & 0xff);
  234.     p[1] = ((w >> 8) & 0xff);
  235. }
  236.  
  237. /*
  238.  * Put long word in memory in 8086 word-reversed format.
  239.  *
  240.  */
  241. ilong(lp, l)
  242. long *lp;
  243. long l;
  244. {
  245.     UWORD *p;
  246.  
  247.     p = (UWORD *)lp;
  248.     iw(&p[0],(UWORD)(l & 0xffff));
  249.     iw(&p[1],(UWORD)((l >> 16) & 0xffff));
  250. }
  251.  
  252. /*
  253.  * Get long word in memory, from 8086 word-reversed format.
  254.  *
  255.  */
  256. glong(al, lp)   /* al is a swaped return long word,*/
  257.                 /* lp is a to be swaped long word */
  258. long *al;
  259. long *lp;
  260.  
  261. {
  262.    char *p, *q;
  263.  
  264.     p = (char *)al;
  265.     q = (char *)lp;
  266.     p[0] = q[3];
  267.     p[1] = q[2];
  268.     p[2] = q[1];
  269.     p[3] = q[0];
  270. }
  271.  
  272. /*
  273.  * Get word in memory, from 8086 byte-reversed format.
  274.  *
  275.  */
  276. UWORD gw(wp, aw)
  277. UWORD *wp;
  278. UWORD *aw;
  279. {
  280.     char *p, *q;
  281.  
  282.     p = (char *)wp;
  283.     q = (char *)aw;
  284.     q[0] = p[1];
  285.     q[1] = p[0];
  286.     return *aw;
  287. }
  288.  
  289.  
  290. /*
  291.  * Stupid delay between writes (.01 second);
  292.  * called in supervisor mode on the ST.
  293.  *
  294.  * The hard disk controller cannot keep up with
  295.  * full-tilt accesses for some reason.
  296.  *
  297.  */
  298. delay()
  299. {
  300.     register long hz200v, *p;
  301.  
  302.     p = (long *)0x4ba;
  303.     hz200v = *p + 2L;        /* compute future value */
  304.     while (*p < hz200v)        /* wait for it to reach that */
  305.     ;
  306. }
  307.  
  308.  
  309. /*
  310.  * Throw up an alert box
  311.  * with the given text.
  312.  *
  313.  */
  314. err(s)
  315. char *s;
  316. {
  317.     ARROW_MOUSE;
  318.     form_alert(1, s);
  319.     BEE_MOUSE;
  320.     return ERROR;
  321. }
  322.  
  323.  
  324. /*
  325.  * Error, concatenate the three strings
  326.  * and throw up an alert box.
  327.  *
  328.  */
  329. errs(s1, s2, s3)
  330. char *s1, *s2, *s3;
  331. {
  332.     strcpy(sbuf, s1);
  333.     strcat(sbuf, s2);
  334.     strcat(sbuf, s3);
  335.     return err(sbuf);
  336. }
  337.  
  338.  
  339. /*
  340.  *  Errcode()
  341.  *    Find error code for previous instruction which returned Check
  342.  *  Condition Status.
  343.  *
  344.  *  Input:
  345.  *    pdev - the physical device number (0 -> 7).
  346.  *  Return:
  347.  *    errnum - the error code.
  348.  */
  349. errcode(pdev)
  350. int pdev;
  351. {
  352.     char data[128];
  353.     extern long rqsense(), ostack;
  354.     UWORD errnum;
  355.     int mask = 0x0001;
  356.     int set, scsidrv;
  357.    
  358.     if (pdev > 15) return ERROR;
  359.     ostack = Super(NULL);
  360.     /* check #pdev device is set or not */
  361.     set = typedev & (mask << pdev);
  362.     scsidrv = typedrv & (mask << pdev);
  363.     if ((set)||(scsidrv)) {    /* if set, it is a removable driver */
  364.         errnum = rqsense(pdev, 16, data);
  365.     } else {    /* if not set, it is a not removable driver */
  366.            errnum = rqsense(pdev, 4, data);
  367.     }
  368.     delay();
  369.     Super(ostack);
  370.     
  371.     if (errnum != 0)
  372.         return err("[1][Fatal error][OK]");
  373.         
  374.     if ((set)||(scsidrv))    { /* if set, it is a removable driver */
  375.         errnum = (UWORD)data[12];
  376.     } else { /* if not set, it is a not removable driver */
  377.         data[0] &= 0x7f;        /* mask out advalid bit */
  378.         errnum = (UWORD)data[0];
  379.     }
  380.     return errnum;        /* return it */
  381. }
  382.  
  383.  
  384. /*
  385.  *  Tsterr()
  386.  *    Given an error code, test if it is a medium change error
  387.  *  or a write protection error.  Put up the appropiate box if
  388.  *  it is either one of those, and return OK.  
  389.  *    If it is not either of those, return ERROR.
  390.  *
  391.  */
  392. tsterr(errnum)
  393. UWORD errnum;
  394. {
  395.     switch(errnum) {
  396.         case MDMCHGD:
  397.             err(mdmchng);
  398.             break;
  399.         
  400.         case WRTPRTD:
  401.             err(wrprotct);
  402.             break;
  403.             
  404.         case DEVNRDY:
  405.             err(drvnrdy);
  406.             break;
  407.             
  408.         default:
  409.             return ERROR;
  410.     }
  411.     return OK;
  412. }
  413.